class Solution {
public:
    int ans = 0;
    int n;

    void dfs(vector<int>& nums, int target, int i, int sum)
    {
        if (i == n)
        {
            if (sum == target) ans++;
            return;
        }
        dfs(nums, target, i + 1, sum + nums[i]);
        dfs(nums, target, i + 1, sum - nums[i]);
    }

    int findTargetSumWays(vector<int>& nums, int target)
    {
        n = nums.size();
        dfs(nums, target, 0, 0);
        return ans;
    }
};